<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE html>
<html lang="zh">
<head>

	<jsp:include page="commonPages/main-style.jsp" flush="true" />
	<link href="css/style.css" rel="stylesheet">

</head>
<body>
<div id="wrapper">
    <div class="header">
        <nav class="navbar   navbar-site navbar-default" role="navigation">
            <div class="container">
                <div class="navbar-header">
                 </div>
                <div class="navbar-collapse collapse">
                    <ul class="nav navbar-nav navbar-right">
                        <li><a href="login.jsp">登录</a></li>
                        <li><a href="signup.jsp">注册</a></li>
                    </ul>
                </div>

            </div>

        </nav>
    </div>

    <div class="main-container">
        <div class="container">
            <div class="row">
                <div class="col-md-8 page-content">
                    <div class="inner-box category-content">
                        <h2 class="title-2"> <i class="icon-user-add"></i>免费注册新用户 </h2>
                        <div class="row">
                            <div class="col-sm-12">
                                <form class="form-horizontal">
                                    <fieldset>
                                        
                                        <div class="form-group required">
                                            <label class="col-md-4 control-label">用户名<sup>*</sup></label>
                                            <div class="col-md-6">
                                                <input id="username" name="username" placeholder="请输入用户名" class="form-control input-md" required="" type="text">
                                            </div>
                                        </div>

                                        <div class="form-group required">
                                            <label for="inputPassword3" class="col-md-4 control-label">密码<sup>*</sup></label>
                                            <div class="col-md-6">
                                                <input id="password" name="password" type="password" class="form-control" required="" placeholder="请输入密码">
                                                <!-- <p class="help-block">至少六个字符</p> -->
                                            </div>
                                        </div>
                                        
                                         
                                        <div class="form-group required">
       
                                        		<label class="col-md-4 control-label"><input class="col-md-6-radio" id="enterprise" name="role" type="radio" value="enterprise"> &nbsp&nbsp企业</label>
                                        		<label class="col-md-4 control-label"><input class="col-md-6-radio" id="individual" name="role" type="radio" value="individual"> &nbsp&nbsp个人</label>
                                        	
                       
                                        </div>
                                         
                                        <div class="form-group">
                                            <label class="col-md-4 control-label"></label>
                                            <div class="col-md-8">
                                               
                                                <div style="clear:both"></div>
                                                <a id="register_button" class="btn btn-primary">注册</a><div id="msg_box" class="bg-danger"></div> 
                                                </div>
                                        </div>
                                    </fieldset>
                                </form>
                            </div>
                        </div>
                    </div>
           
            </div>
        </div>
    </div>
</div>
	
    <jsp:include page="commonPages/main-script.jsp" flush="true" />
</body>

<script type="text/javascript">
		$(document).ready(function(){
			
			$("#register_button").click(function(){
				register_button_click();
			});
			
			$("#username").blur(function(){
				  checkUserName();
				});
			
			$("#username,#password,#veryCode").focus(function(){
				hiddenMsgBox();
			});
			
		});
		
		    
		
		//点击注册按钮
		function register_button_click(){
			
			
			
			var username = $("#username").val();
			var password = $("#password").val();
			var role = "";
			
			var radio = document.getElementsByName("role");  
	        for (i=0; i<radio.length; i++) {  
	            if (radio[i].checked) { 
	                role = radio[i].value; 
	            }  
	        }
			
			if(username == ""){
				showMsgBox("请输入用户名！");
			}else if(password == ""){
				showMsgBox("请输入密码！");
			}else{
				//注册
				$.ajax({     
			        type:"POST",     
			        url:"user/register", 
			        data:{
		        		username : username,  
		        		password : password, 
		        		role : role,
		        		
		        	},    
			        success:function(result) {
			        	//返回数据根据结果进行相应的处理  
                        if (result == "注册成功，请登录！") {  
                        	alert(result);
                        	location.href = "index"
                        } else{  
                        	showMsgBox(result);
                        }  
                    },
                    error:function(){
                    	alert("异常");
                    }
			    });
			}
		}
		
		function showMsgBox(msg){
			$("#msg_box").html(msg);
			$("#msg_box").css("display","block");
		}
		function hiddenMsgBox(){
			
			$("#msg_box").css("display","none");
		}
		
	</script>
</html>

